<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户反馈列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">

                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item">

                                <div class="layui-inline">
                                    <label class="layui-form-label">用户ID</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input class="layui-input" name="userId" placeholder="请输入用户ID" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">创建时间</label>
                                    <div class="layui-input-block">
                                        <div class="layui-inline">
                                            <input type="text" name="startCreateTime" class="layui-input time-select" placeholder="开始时间" autocomplete="off">
                                        </div>
                                        <div class="layui-inline">至</div>
                                        <div class="layui-inline">
                                            <input type="text" name="endCreateTime" class="layui-input time-select" placeholder="结束时间" autocomplete="off">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit
                                            lay-filter="LAY-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"> 搜索</i>
                                    </button>
                                </div>
                            </div>
                        </div>
                        <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                        <script type="text/html" id="status">
                            {{#  if(d.status == 1){ }}
                            <input type="checkbox" name="status" lay-skin="switch" checked disabled lay-text="已回复|未回复">
                            {{#  } else { }}
                            <input type="checkbox" name="status" lay-skin="switch" disabled lay-text="已回复|未回复">
                            {{#  } }}
                        </script>

                        <script type="text/html" id="test-table-reload-barDemo">
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/sys/editFeedback')} layui-hide #{/if}" lay-event="edit"><i class="layui-icon layui-icon-chat"></i>回复</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util', 'form', 'laydate'], function () {
        var $ = layui.$,
                table = layui.table,
                form = layui.form,
                laydate = layui.laydate,
                util = layui.util,
                admin = layui.admin;

        //监听搜索
        form.on("submit(LAY-search)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload', {
                where: field
            });
        });

        //时间选择器，同时绑定多个
        lay('.time-select').each(function () {
            laydate.render({
                elem: this
                , trigger: 'click'
                , theme: 'molv'
                , type: 'datetime'
            });
        });

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            , url: "/sys/getFeedbackList"
            , toolbar: '#test-table-reload-toolbar'
            , defaultToolbar: ['filter']
            , cellMinWidth: 80
            , cols: [[
                {field: 'userId', title: '用户ID', fixed: true}
                , {field: 'content', title: '反馈内容', width: 600, templet: function (d) {
                        return "<div>" + util.escape(d.content) + "</div>";
                    }}
                , {field: 'createTime', title: '创建时间', sort: true, templet: function (d) {
                        return "<div>" + util.toDateString(d.createTime) + "</div>";
                    }}
                , {field: 'status', title: '回复状态', templet: '#status'}
                , {field: 'contact', title: '联系方式'}
                , {fixed: 'right', title: '操作', toolbar: '#test-table-reload-barDemo', width: 120}
            ]]
            , page: true
            , height: 522
        });

        //监听行工具事件
        table.on('tool(test-table-reload)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '回复内容'
                    , skin: 'layui-layer-lan'
                    , shade: [0.5, '#393D49']  //遮罩透明度
                    , anim: 1 //0-6的动画形式，-1不开启
                    , content: '/sys/editFeedback?id=' + data.id
                    , area: ['600px', '300px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                                , submit = layero.find('iframe').contents().find("#editFeedbackSubmit");
                        //监听提交
                        iframeWindow.layui.form.on('submit(editFeedbackSubmit)', function (data) {
                            var field = data.field; //获取提交的字段
                            if (field.reply === "") {
                                return layer.msg("回复内容不能为空", {time: 2000});
                            }
                            $.post("/sys/replyFeedback", field, function (result) {
                                if (result.code > 0) {
                                    layer.msg(result.msg, {icon: 2});
                                } else {
                                    layer.msg(result.msg, {icon: 1, time: 2000});
                                    window.location.reload();
                                }
                            });
                            layer.close(index); //关闭弹层
                        });
                        submit.trigger('click');
                    }
                });
            }
        });

    });
</script>
</body>
</html>